<?php

class FormTabControl extends FormControl {
	
	public function __construct() { 
		parent::__construct(array(
			'wbtype' => 'TabControl',
			'x' => 0,
			'y' => 0,
			'caption' => 'page1',
			'width' => 100,
			'height' => 100
		));
	}


	/**
	 * 컨트롤 그리기 
	 * 
	 * @param WBGraphics $graphics
	 */
	public function displayControl(WBGraphics $g) {

		$xstart = $this->getOption('x');
		$ystart = $this->getOption('y');
		$width = $this->getOption('width');
		$height = $this->getOption('height');		
		$caption = $this->getOption('caption');		
		$style = $this->getOption('style');		
	
		$xend = $xstart + $width;
		$yend = $ystart + $height;	
	
		$xtab = 0;
		if ($caption) { 
			$pages = explode(",", $caption);
			$count = count($pages);
			$tabheight = 20;
			
			for ($i = 0; $i < $count; $i++) { 
				$xtab += $this->displayTab($g, $pages[$i], $xstart+$xtab, $ystart, $tabheight, $style);
				if ($i == 0) { 
					$xtab1 = $xtab - 2;
				}
			}
		} else { 
			$tabheight = 0;
			$tabWidth = 0;
		}
		
		if (ProjectManager::$checkWireFrame->isChecked()) { 
			$g->rect($xstart,  $ystart + $tabheight - 1, $width, $height - $tabheight - 1, FormControl::SHADE, false, 1, WBGraphics::LINE_DASHES_2);
		} else { 
			$g->rect($xstart, $ystart + $tabheight - 1, $width, $height - $tabheight - 1, FormControl::FACE, true);
			$g->line($xend - 2, $ystart + $tabheight - 1, $xend - 2, $yend - 2, FormControl::SHADE);
			$g->line($xstart, $yend - 2, $xend - 2, $yend - 2, FormControl::SHADE);
			$g->line($xstart + $xtab1, $ystart + $tabheight - 1, $xend - 2, $ystart + $tabheight - 1, FormControl::HILITE);
			$g->line($xstart, $ystart + $tabheight - 1, $xstart, $yend - 2, FormControl::HILITE);
			$g->line($xend - 1, $ystart + $tabheight - 1, $xend - 1, $yend - 1, FormControl::SHADOW);
			$g->line($xstart, $yend - 1, $xend - 2, $yend - 1, FormControl::SHADOW);
		}
	}
	
	public function displayTab($g, $caption, $xstart, $ystart, $height, $style) { 

		$size = wb_get_size($caption);
		$width = max(40, $size[0] + 16);
	
		$xend = $xstart + $width;
		$yend = $ystart + $height;
	
		if(ProjectManager::$checkWireFrame->isChecked()) {
			$g->rect($xstart, $ystart, $width, $height, FormControl::SHADE, false, 1, WBGraphics::LINE_DASHES_2);
		} else {
			$g->rect($xstart, $ystart, $width, $height, FormControl::FACE, true);
			$g->line($xend - 2, $ystart, $xend - 2, $yend - 2, FormControl::SHADE);
			$g->line($xstart, $ystart, $xend - 2, $ystart, FormControl::HILITE);
			$g->line($xstart, $ystart, $xstart, $yend - 2, FormControl::HILITE);
		}
	
		// Draw tab text
	
		$font = ($this['disabled']) ? self::$disabledFont : self::$realFont;
		
		$g->text($caption, $xstart + 8, $ystart, $width, $height, $font, WBC_LEFT | WBC_MIDDLE);
		return $width;
	}
	
	public function getProperty() { 
		return self::$property;
	}	
}


?>